<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="midHostname" value='<%=ServerValue.getMidHostname()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="${midContextPath}/css/smoothness.datepick.css" />
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.alphanumeric.js"></script>
<!-- FLASH -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.flash.js"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/yaodian100.common.js"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.autotab-1.1b.js"></script>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});

		$(":input[id*='adWord']").alphanumeric();
		$(":input[id*='adWord']").autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });
		
		$(":input[name*='idxLayoutType']").each(function(){
			if ( this.value == 'FLASH'){
				$("#objId").flash(
	        { src: "${midHostname}/eventImg/" + $("#idxImgFolder").val() + "/" + $("#advType").val() + "/" + $("#idxImgName").val(),
	          width: 340,
	          height: 180 },
	        { version: 8 }
				);
			}else if("${advId}"!=""){
				$("#objId").html("<img src='${midHostname}/eventImg/" + $("#idxImgFolder").val() + "/" + $("#advType").val() + "/" + $("#idxImgName").val() + "' width='340' height='180'/><br/>");
			}
		});

		$("#idxLayoutType").change(function(){
			$("#idxImg").val("");
			$("#idxImgName").val("");
			$("#idxImgFolder").val("");
			$("#idxImgCorrect").val("");
		});

		$("#subBtn").click(function(){
			$("#advStatus").val("10");
			if ( validate_data() ){
				$("#mainGoldAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			$("#advStatus").val("00");
			if ( validate_data() ){
				$("#mainGoldAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			$("#advStatus").val("90");
			if ( validate_data() ){
				$("#mainGoldAdvForm").submit();
			}
		});
		$("#idxImg").change(function(){checkImg(document.mainGoldAdvForm.idxImg,35,340,180,$("#idxImgCorrect"),"") ;});

		/*清除圖檔*/
		$("#clearImg").click(function(event){
			event.preventDefault();
			$("#idxImg").val('');
			$("#idxImgCorrect").val('');
		});
	});
	
	function validate_data(){
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
		}
		if ( $("#startDate").val() == ""){
			alert("请输入起始时间");
			$("#startDate").focus();
			return false;
		}

		if( $("#endDate").val() == "" ){
			alert("请输入结束时间");
			$("#endDate").focus();
			return false;
		}

		if($('#startDate').val()>$('#endDate').val()){
			alert('结束日期不能小于起始日期');
			$('#endDate').focus();
			return false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				alert('结束时间需大于起始时间');
				$('#endTime').focus();
				return false;
			}
		}

		if ( $("#advId").val() == "" && $('#doClone').val() != 'true' ){
			if ( $("#idxImg").val() == "" ){
				alert("请输入厂商Banner图片");
				$("idxImg").focus();
				return false;
			}
		}
		if ( $("#idxImgLink").val() == "" ){
			alert("请输入图片点击连结");
			$("#idxImgLink").focus();
			return false;
		}
		if ( !isURL($("#idxImgLink").val()) ){
			alert("图片点击连结格式错误");
			$("#idxImgLink").focus();
			return false;
		}
		if ( $("#idxImg").val() != "" ){
			if ( $("#idxLayoutType").val() == "FLASH" && $("#idxImg").val().indexOf(".swf") == -1 ){
				alert("檔案格式错误,请上传flash檔");
				$("#idxImg").focus();
				return false;
			}
			if ( $("#idxLayoutType").val() == "IMG" && ( $("#idxImg").val().toLowerCase().indexOf(".gif") == -1 && $("#idxImg").val().toLowerCase().indexOf(".jpg") == -1 )){
				alert("檔案格式错误,请上传gif/jpg檔");
				$("#idxImg").focus();
				return false;
			}
			if($("#idxImgCorrect").val()!=''){
				alert($("#idxImgCorrect").val());
				$("#idxImg").focus();
				return false;
			}
			$("#idxImgName").val($("#idxImg").val());		
		}
		
		/*
		if($("#adWord").val()==''){
			alert('此处广告代码为必填项');
			$("#adWord").focus();
			return false;
		}
		*/
		
		return true;
	}
</script>
<h1>
	广告管理 - 品牌折扣馆 厂商Banner<br />
	<div class="f-link">
		<a href="${midContextPath}/generate/search.do">回广告查询页</a>
	</div>
</h1>
<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>
<s:form action="mainGold/saveOutletsBannerAdv.do" method="post" name="mainGoldAdvForm" id="mainGoldAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>
					品牌折扣馆 - 厂商Banner
					<input type="hidden" id="advType" name="advType" value="${advType}"/>
				</td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td>
					<input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/>
					<s:if test="null != fieldErrors['advName']">
					<br/>
					<p><span class="msg rn"><s:fielderror><s:param>advName</s:param></s:fielderror></span></p>
					</s:if>
				</td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
					<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
					<select id="startTime" name="startTime">			
						<c-rt:forEach begin="0" end="23" var="t1">
							<c-rt:if test="${t1<10}">
							<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<c-rt:if test="${t1>=10}">
							<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
						</c-rt:forEach>
					</select>  
					~ 
					<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
					<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
					</select>
					<s:if test="null != fieldErrors['startDate']">
					<br/>
					<p><span class="msg rn"><s:fielderror><s:param>startDate</s:param></s:fielderror></span></p>
					</s:if>
					<s:if test="null != fieldErrors['endDate']">
					<br/>
					<p><span class="msg rn"><s:fielderror><s:param>endDate</s:param></s:fielderror></span></p>
					</s:if>					
				</td>
			</tr>
			<tr>
				<th>图檔设定</th>
				<td>
					<div id="objId"></div><br/>
					<b>厂商Banner内容型态:</b>
					<select name="idxLayoutType" id="idxLayoutType">
						<option value="IMG" ${idxLayoutType eq 'IMG' ? 'selected' : '' }>图(340X180)</option>
<!-- 						<option value="FLASH" ${idxLayoutType eq 'FLASH' ? 'selected' : '' }>FLASH(340X180)</option> -->
					</select>	
					<s:if test="null != fieldErrors['idxLayoutType']">
					<br/>
					<p><span class="msg rn"><s:fielderror><s:param>idxLayoutType</s:param></s:fielderror></span></p>
					</s:if>		
					<br/>							
					<b>厂商Banner图片:</b><s:file id="idxImg" name="idxImg" value="" size="60" ></s:file><input type="button" value="清除图檔" id="clearImg"/>
					<s:if test="null != fieldErrors['idxImg']">
					<br/>			
					<p><span class="msg rn"><s:fielderror><s:param>idxImg</s:param></s:fielderror></span></p>
					</s:if>	
					<br/><span>340X180 &lt;35k</span><br/>			
					<b>图片点击连结:</b><input type="text" name="idxImgLink" id="idxImgLink" value="${idxImgLink}" size="60"/><br/><span>ex:http://www.yaodian100.com</span>
					<br/><input type="hidden" id="idxImgCorrect" value="Y"/>
					<s:if test="null != fieldErrors['idxImgLink']">
					<p><span class="msg rn"><s:fielderror><s:param>idxImgLink</s:param></s:fielderror></span></p>
					</s:if>
					<b>显示顺序：</b>
						<select name="idxShowSeq" id="idxShowSeq">
							<c-rt:forEach begin="1" end="3" var="i">
								<option value="${i}" ${i eq idxShowSeq ? 'selected' : ''}>${i}</option>
							</c-rt:forEach>
						</select>
					<br/><b>广告代码:</b><input type="text" id="adWord" name="adWord" value="${adWord}" size="20" maxlength="25"/><span>由英文字母、数字组成，最多25个半角</span>
					<input type="hidden" id="idxImgName" name="idxImgName" value="${idxImgName}"/>
					<input type="hidden" id="idxImgFolder" name="idxImgFolder" value="${idxImgFolder}"/>				
				</td>
			</tr>
		<c-rt:if test="${not empty advId}">
			<tr>
				<th>修改记录</th>
				<td>
					<p>建立：<fmt:formatDate value="${createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${createUser}</p>
					<p>修改：<fmt:formatDate value="${modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${modifyUser}</p>
				</td>
			</tr>
		</c-rt:if>
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="from" name="from" value="${from}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<s:hidden id="doClone" name="doClone" />
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>